package com.zengqingfa.designpattern.structure.proxy.dynamic;

/**
 *
 * @fileName: Client
 * @author: zengqf3
 * @date: 2021-4-22 9:00
 * @description:
 */
public class Client {

    public static void main(String[] args) {
        Subject realSubject=new RealSubject();
        ProxyFactory proxyFactory = new ProxyFactory(realSubject);
        Subject proxy = (Subject) proxyFactory.getProxyInstance();
        //real subject method
        String method = proxy.method();
        System.out.println(method);
        //com.zengqingfa.designpattern.structure.proxy.dynamic.RealSubject@6e8cf4c6
        System.out.println(realSubject);
        //proxy 返回null
        //sout时,会调用对象的toString方法,
        // 所以返回值为null,toString的返回结果就是null,因此输出到控制台的结果为null.
        System.out.println(proxy);
        //代理类的类型：class com.sun.proxy.$Proxy0
        System.out.println("代理类的类型："+proxy.getClass());

        //生成代理类
        // 保存JDK动态代理生成的代理类，类名保存为 RealSubjectProxy
        ProxyUtils.generateClassFile(realSubject.getClass(), "realSubjectProxy");
    }
}
